#include "createnewathlete.h"
#include "ui_createnewathlete.h"

CreateNewAthlete::CreateNewAthlete(SystemController *systemController, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CreateNewAthlete)
{
    ui->setupUi(this);
    this->systemController = systemController;
    ui->genderComboBox->addItem(tr("male"), "male");
    ui->genderComboBox->addItem(tr("female"), "female");
}

CreateNewAthlete::~CreateNewAthlete()
{
    delete ui;
}

/*!
  \fn accecpt
  Function callend when dialog accepted
  */
void CreateNewAthlete::accept()
{
    bool acceptForm = true;
    if (getName() == "")
    {
        this->systemController->showErrorDialog(this, tr("Field has no value"), tr("Please insert a text into the field \"Name\""));
        acceptForm = false;
        return;
    }

    if (getFirstName() == "")
    {
        this->systemController->showErrorDialog(this, tr("Field has no value"), tr("Please insert a text into the field \"First name\""));
        acceptForm = false;
        return;
    }

    if (getPhone() == "")
    {
        this->systemController->showErrorDialog(this, tr("Field has no value"), tr("Please insert a text into the field \"Phone\""));
        acceptForm = false;
        return;
    }

    if (acceptForm)
        QDialog::accept();
}
///////////////////
//Getter Methods//
/////////////////
QString CreateNewAthlete::getName()
{
    return this->ui->lineEdit->text();
}

QString CreateNewAthlete::getFirstName()
{
    return this->ui->firstNameLineEdit->text();
}

QDate CreateNewAthlete::getBirtDate()
{
    return this->ui->birthDateLineEdit->date();
}

QString CreateNewAthlete::getGender()
{
    return this->ui->genderComboBox->itemData(this->ui->genderComboBox->currentIndex()).toString();
}

QString CreateNewAthlete::getPhone()
{
    return this->ui->phoneLineEdit->text();
}

QString CreateNewAthlete::getMobile()
{
    return this->ui->mobileLineEdit->text();
}

QString CreateNewAthlete::getMail()
{
    return this->ui->mailLineEdit->text();
}

QDate CreateNewAthlete::getCIdExp()
{
    return this->ui->cIdExpDateLineEdit->date();
}

